package org.goldenport.g3.app

import org.goldenport.g3._
import org.goldenport.g3.atom._
import org.goldenport.g3.messages._
import org.goldenport.g3.messages.http._
import org.goldenport.g3.events.Getted

/**
 * @since   Dec. 31, 2010
 * @version Jan. 29, 2011
 * @version Dec.  4, 2011
 * @author  ASAMI, Tomoharu
 */
class ExtjsHandson extends G3Application with UseRecord {
  port("/") html(<p>Ext-JS Hands-on</p>)

  port("/handson/locations") agent {
    case _ => {
      RecordSet(Record('country -> "JP",
                       'loc -> "CTS",
                       'name -> "新千歳空港",
                       'n -> 42.787621,
                       'e -> 141.68147))
    }
  }

  port("/handson/browsers") agents {
    RecordSet(
      Record("id" -> 1,
             "name" -> "IE",
             "percentage" -> 62.18),
      Record("id" -> 2,
             "name" -> "Firefox",
             "percentage" -> 24.41),
      Record("id" -> 3,
             "name" -> "Chrome",
             "percentage" -> 5.20),
      Record("id" -> 4,
             "name" -> "Safari",
             "percentage" -> 4.51),
      Record("id" -> 5,
             "name" -> "Opera",
             "percentage" -> 2.38),
      Record("id" -> 6,
             "name" -> "Opera Mini",
             "percentage" -> 0.59))
  }

  port("/handson/browservers") agents {
    RecordSet(
      Record("id" -> 1,
             "name" -> "IE",
             "version" -> "8",
             "percentage" -> 22.31),
      Record("id" -> 2,
             "name" -> "IE",
             "version" -> "6",
             "percentage" -> 24.61),
      Record("id" -> 3,
             "name" -> "Firefox",
             "version" -> "3.5",
             "percentage" -> 17.10),
      Record("id" -> 4,
             "name" -> "IE",
             "version" -> "7",
             "percentage" -> 14.58),
      Record("id" -> 5,
             "name" -> "Firefox",
             "version" -> "3.0",
             "percentage" -> 5.29),
      Record("id" -> 6,
             "name" -> "Chrome",
             "version" -> "3.0",
             "percentage" -> 0.53),
      Record("id" -> 7,
             "name" -> "Safari",
             "version" -> "4.0",
             "percentage" -> 3.55),
      Record("id" -> 8,
             "name" -> "IE",
             "version" -> "8互換モード",
             "percentage" -> 2.79),
      Record("id" -> 9,
             "name" -> "Opera",
             "version" -> "10",
             "percentage" -> 1.65),
      Record("id" -> 10,
             "name" -> "Chrome",
             "version" -> "4.0",
             "percentage" -> 1.75),
      Record("id" -> 11,
             "name" -> "Firefox",
             "version" -> "3.6",
             "percentage" -> 1.07),
      Record("id" -> 12,
             "name" -> "Firefox",
             "version" -> "2.0",
             "percentage" -> 0.79),
      Record("id" -> 13,
             "name" -> "Opera",
             "version" -> "9",
             "percentage" -> 0.70))
  }

  port("/handson") invoke('ds)

  val schema_todo = Schema(IdField,
                           'title,
                           ('date, XDate),
                           ('memo, XString, MZeroOne))
  val schema_todo_auto = Schema(AutoIdField,
                                'title,
                                ('date, XDate),
                                ('memo, XString, MZeroOne))
  val schema_check = Schema(AutoIdField,
                            ('length, XToken, XLength(5)),
                            ('lengthrange, XToken, XMinLength(3), XMaxLength(6)),
                            ('intrange, XUnsignedInt, XMaxExclusive(10))
                            )
  val schema_issue = Schema(AutoIdField,
                            ('subject, XToken),
                            ('date, XDate),
                            ('time, XTime, MZeroOne),
                            ('sex, XToken, XEnumeration("m", "f"), MZeroOne),
                            ('age, XUnsignedInt, MZeroOne),
                            ('content, XString, MZeroOne)
                            )

  datastore('ds,
            RecordClassSpace(
              RecordClass('todo, schema_todo_auto),
              RecordClass('todo00, schema_todo_auto),
              RecordClass('todo01, schema_todo_auto),
              RecordClass('todo02, schema_todo_auto),
              RecordClass('todo03, schema_todo_auto),
              RecordClass('todo04, schema_todo_auto),
              RecordClass('todo05, schema_todo_auto),
              RecordClass('todo06, schema_todo_auto),
              RecordClass('todo07, schema_todo_auto),
              RecordClass('todo08, schema_todo_auto),
              RecordClass('todo09, schema_todo_auto),
              RecordClass('todo10, schema_todo_auto),
              RecordClass('todo11, schema_todo_auto),
              RecordClass('todo12, schema_todo_auto),
              RecordClass('todo13, schema_todo_auto),
              RecordClass('todo14, schema_todo_auto),
              RecordClass('todo15, schema_todo_auto),
              RecordClass('todo16, schema_todo_auto),
              RecordClass('todo17, schema_todo_auto),
              RecordClass('todo18, schema_todo_auto),
              RecordClass('todo19, schema_todo_auto),
              RecordClass('todo20, schema_todo_auto),
              RecordClass('issue, schema_issue),
              RecordClass('issue00, schema_issue),
              RecordClass('issue01, schema_issue),
              RecordClass('issue02, schema_issue),
              RecordClass('issue03, schema_issue),
              RecordClass('issue04, schema_issue),
              RecordClass('issue05, schema_issue),
              RecordClass('issue06, schema_issue),
              RecordClass('issue07, schema_issue),
              RecordClass('issue08, schema_issue),
              RecordClass('issue09, schema_issue),
              RecordClass('issue10, schema_issue),
              RecordClass('issue11, schema_issue),
              RecordClass('issue12, schema_issue),
              RecordClass('issue13, schema_issue),
              RecordClass('issue14, schema_issue),
              RecordClass('issue15, schema_issue),
              RecordClass('issue16, schema_issue),
              RecordClass('issue17, schema_issue),
              RecordClass('issue18, schema_issue),
              RecordClass('issue19, schema_issue),
              RecordClass('issue20, schema_issue),
              RecordClass('validcheck, schema_check)))
}
